
/**
 * 解析 RTSP 视频流，得到 h264 码流包，将 H264 码流包存放到环形缓冲区中
 */

#ifndef _DEMUXER_RTSP_H_
#define _DEMUXER_RTSP_H_

#include "ringbuffer.hpp"
#include <cstring>
#include <iostream>
#include <thread>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
}

class demuxer_rtsp {
private:
    std::string ip;
    std::string url;
    std::thread handle;
    ringbuffer* rbuf;
    bool running = false;

    AVFormatContext* fmtctx;
    AVCodecParameters* codecpar;
    AVStream* stream;
    AVPacket* packet;
    int index;

public:
    demuxer_rtsp();
    demuxer_rtsp(std::string url, ringbuffer* ringbuffer, std::string ip);
    ~demuxer_rtsp();

    int set(std::string url, ringbuffer* ringbuffer, std::string ip);
    void thread();
    int init();
    void deinit();
    int reinit();
    void start();
    void stop();

    void msleep(int ms);
};

#endif